package com.artevivo.comparadores;

import java.util.Comparator;

import com.artevivo.entidades.Curso;

public class ComparadorCursosPorDiasHoras implements Comparator<Curso> {

    @Override
    public int compare(Curso c1, Curso c2) {
        int comparation = -1;

        String[] diasDeLaSemana = new String[] { "Lunes", "Martes", "Miercoles", "Jueves", "Viernes" };
        Integer c1Index = -1;
        Integer c2Index = -1;
        for (int i = 0; i < diasDeLaSemana.length; i++) {
            if (diasDeLaSemana[i].equals(c1.getDia())) {
                c1Index = i;
            }
            if (diasDeLaSemana[i].equals(c2.getDia())) {
                c2Index = i;
            }
        }

        comparation = c1Index.compareTo(c2Index);
        if (comparation != 0) {
            return comparation;
        }

        String c1HoraInicio = c1.getHora().split("-")[0];
        String c2HoraInicio = c2.getHora().split("-")[0];
        comparation = c1HoraInicio.compareTo(c2HoraInicio);

        return comparation;
    }
}
